var TableManaged = function () {

    var initTable1 = function ($obj) {

        //var table = $('#sample_1');
       var table = $obj;
        // begin first table
		        table.dataTable({
					// "bLengthChange": false,
					// "bFilter": false,
					// "pagingType": "bootstrap_extended",
					//"bProcessing" : true,
		        	"processing": true,//是否显示处理状态(排序的时候，数据很多耗费时间长的话，也会显示这个)
					"bFilter" : false,
					"stateSave": true,//保存状态 - 在页面重新加载的时候恢复状态（页码等内容）
					"searching": false,//是否允许Datatables开启本地搜索
					"ordering" : false,//是否允许Datatables开启排序
					"dom" : 'rt<"#bottom"ilp<"clear">>',//定义DataTables的组件元素的显示和显示顺序
					/*"pageLength" : ,*/
					"pagingType": "full_numbers",//分页类型
					"serverSide" : true,//是否开启服务器模式
					"sAjaxSource" : "/admin/adminuser/list",//ajax 数据地址 使用该配置比ajax{} 配置好
					"sServerMethod" : "POST",//ajax method
					/*"fnServerData": function ( sSource, aoData, fnCallback ) {
						              $.ajax( {
						                  "dataType": 'json',
						              "type": "POST",
						              "url": sSource,
						              "data": aoData,
						              "success": fnCallback
						              } );
						          },*/
					 "fnServerParams": function ( aoData ) {
						 var qdata = $("#queryForm").serializeArray();
						 if(qdata!=null){
							 for(var i = 1;i<qdata.length;i++){
								 aoData.push( qdata[i] );
							 }
						 }
					 },
					/*
					 * "processing": true, "serverSide": true, "ajax": {
					 * url:"/admin/adminuser/list", },
					 */
					"columns" : [//设定列的所有初始属性

					{
						'data' : 'id'
					}, {
						'data' : 'uname'
					}, {
						'data' : 'nickname'
					}, {
						'data' : 'rolename'
					},

					],
					"columnDefs" : [//设置定义列的初始属性	
							{
								"render" : function(data, type, row) {
									var td = '<td><input type="checkbox" name="idS" class="checkboxes" value='
											+ data + ' /></td>';
									return td;
								},
								"targets" : 0
							} ],
					"language" : {//定义方言
						"processing":"正在加载数据中...",//当table处理用户处理信息时，显示的信息字符串
						"loadingRecords": "正在加载数据...",//加载数据时的提示信息 - 当 Ajax请求数据时显示
						"emptyTable":"暂无数据",//当表格没有数据时，表格所显示的字符串
						"info" : "显示  _START_ 至  _END_ 项结果,共 _TOTAL_ 项",
						"infoEmpty": "显示第 0 至 0 项结果，共 0 项",
						"lengthMenu" : "  每页显示 _MENU_ 项",
						"infoFiltered":"",//当表格搜索后，在汇总字符串上需要增加的内容
						"paginate" : {
							"previous" : "上一页",
							"next" : "下一页",
							"last" : "尾页",
							"first" : "首页"
						}
					},
					"lengthMenu" : [ [ 10, 50, 100, 500],
					                 [ 10, 50, 100, 500]
									]//分页数
					/*,"initComplete": function(settings, json) {
						Metronic.initAjax();
					  }*/
				/*
				 * "columns": [{ "orderable": false }, { "orderable": true }, {
				 * "orderable": false }],
				 */
				/*
				 * "bLengthChange": false, "bFilter": false, "bSort": false,
				 * "iDisplayLength": 10, //"sPaginationType": "full_numbers",
				 * "bProcessing": true, "bServerSide": true,
				 * "sAjaxDataProp":"datas", "sAjaxSource":
				 * "/admin/adminuser/list", "sServerMethod": "POST",
				 * "aoColumns": [ { "datas": "uname" }, { "datas": "nickname" }, {
				 * "datas": "rolename" } ]
				 */// Internationalisation. For more info refer to
					// http://datatables.net/manual/i18n
				/*
				 * "language": { "aria": { "sortAscending": ": activate to sort
				 * column ascending", "sortDescending": ": activate to sort
				 * column descending" }, "emptyTable": "No data available in
				 * table", "info": "Showing _START_ to _END_ of _TOTAL_
				 * entries", "infoEmpty": "No entries found", "infoFiltered":
				 * "(filtered1 from _MAX_ total entries)", "lengthMenu": "Show
				 * _MENU_ entries", "search": "Search:", "zeroRecords": "No
				 * matching records found" },
				 */

				// Uncomment below line("dom" parameter) to fix the dropdown
				// overflow issue in the datatable cells. The default datatable
				// layout
				// setup uses scrollable div(table-scrollable) with
				// overflow:auto to enable vertical scroll(see:
				// assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js).
				// So when dropdowns used the scrollable div should be removed.
				// "dom": "<'row'<'col-md-6 col-sm-12'l><'col-md-6
				// col-sm-12'f>r>t<'row'<'col-md-5 col-sm-12'i><'col-md-7
				// col-sm-12'p>>",
				/*
				 * "bStateSave": true, // save datatable state(pagination, sort,
				 * etc) in cookie. "bPaginate":true, "columns": [{ "orderable":
				 * false }, { "orderable": true }, { "orderable": false }, {
				 * "orderable": false }, { "orderable": true }, { "orderable":
				 * false }],
				 */

				/*
				 * "lengthMenu": [ [5, 15, 20, -1], [5, 15, 20, "All"] // change
				 * per page values here ],
				 */
				// set the initial value
				/* "pageLength": 5, */
				/*
				 * "pagingType": "bootstrap_full_number", "language": {
				 * "search": "My search: ", "lengthMenu": " _MENU_ records",
				 * "paginate": { "previous":"上一页", "next": "下一页", "last": "尾页",
				 * "first": "首页" } }, "columnDefs": [{ // set default column
				 * settings 'orderable': false, 'targets': [0] }, {
				 * "searchable": false, "targets": [0] }], "order": [ [1, "asc"] ]
				 */// set first column as a default sort by asc
				});
        table.on( 'draw.dt', function () {//绑定datatable 的绘制事件
            Metronic.initAjax();
        } );
        var tableWrapper = jQuery('#sample_1_wrapper');
        table.find('.group-checkable').change(function () {
            var set = jQuery(this).attr("data-set");
            var checked = jQuery(this).is(":checked");
            jQuery(set).each(function () {
                if (checked) {
                    $(this).attr("checked", true);
                    $(this).parents('tr').addClass("active");
                } else {
                    $(this).attr("checked", false);
                    $(this).parents('tr').removeClass("active");
                }
            });
            jQuery.uniform.update(set);
        });

       /* table.on('change', 'tbody tr .checkboxes', function () {
            $(this).parents('tr').toggleClass("active");
        });*/

        tableWrapper.find('.dataTables_length select').addClass("form-control input-xsmall input-inline"); // modify table per page dropdown
    }
    var initTable2 = function ($obj) {
    	var table = $obj;
    	table.dataTable( {
    		"processing": true,
    	    "language" : {
				//"infoEmpty": "暂无数据",
			"emptyTable":"无数对对对据",
			"processing":"chuli..."
    	    	},
    	} );
    }
    return {

        //main function to initiate the module
        init: function ($obj) {
            if (!jQuery().dataTable) {
                return;
            }
            initTable1($obj);
        }

    };

}();